<template>
	<view class="page">
		<view class="info_box">
			<view @click="backXj"
				style="display: flex;flex-direction: row;align-items: center;margin-top: 20rpx;font-size: 28rpx;">
				<u-icon name="arrow-left" color="#999" style="margin-top: 5rpx;" size="18"></u-icon>
				<text>返回</text>
			</view>
			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">巡检工作包：{{baseInfo.work_package_title}}
				</view>
				<view class="info_box_base_item">巡检方式：现场巡检</view>
				<view class="info_box_base_item">工单说明：<text class="base_item_dd">{{baseInfo.work_orderdesc}}</text>
				</view>
				<view class="info_box_base_item">工单时间 ：{{baseInfo.create_time}}</view>
			</view>

			<view class="xj_map">
				<view class="xj_map_type"> 
					<view class="xj_map_type_item" :class="dataType==1?'xj_map_type_item_active':''" @click="changeType(1)">地图显示</view>
					<view class="xj_map_type_item" :class="dataType==2?'xj_map_type_item_active':''" @click="changeType(2)">列表显示</view>
				</view>
				<map @markertap="markTap" v-show="dataType == 1" style="width: 100%; height: 60vh;" scale="10" :latitude="first.latitude"
					:longitude="first.longitude" :enable-cluster="true" :markers="covers">
				</map> 
				<view class="kcsj_box" v-show="dataType == 2">
					<view class="kcsj_box_item" v-for="(item,index) in packList">
						<view class="kcsj_box_item_top">
							<view class="kcsj_box_item_top_left">
								站点名称:{{item.title}}
							</view>
							<view class="kcsj_box_item_top_right" v-if="item.status == 0" @click="gotoInfo(item)">
								<view class="kcsj_box_item_top_right_btn">待处理</view>
								<u-icon name="arrow-right" color="rgb(119, 119, 119)" size="16"></u-icon>
							</view>
							<view class="kcsj_box_item_top_right" v-if="item.status == 1">
								<view class="kcsj_box_item_top_right_btn">待审核</view>
								<u-icon name="arrow-right" color="rgb(119, 119, 119)" size="16"></u-icon>
							</view>
							<view class="kcsj_box_item_top_right" v-if="item.status == 2">
								<view class="kcsj_box_item_top_right_btn"
									style="border: 1px solid rgb(100, 200, 80);color:rgb(100, 200, 80)">通过</view>
								<u-icon name="arrow-right" color="rgb(100, 200, 80)" size="16"></u-icon>
							</view>
							<view class="kcsj_box_item_top_right" v-if="item.status == 3" @click="gotoInfo(item)">
								<view class="kcsj_box_item_top_right_btn">拒绝</view>
								<u-icon name="arrow-right" color="rgb(119, 119, 119)" size="16"></u-icon>
							</view>

						</view>
						<view class="kcsj_box_item_bottom">
							创建时间:{{item.create_time}}
						</view>
					</view>
				</view>
			</view>

			<view class="btn">提交</view>
		</view>
		<bottom c_value="3" ref="bot"></bottom>
	</view>
</template>

<script>
	import {
		api,
		apiBaseUrl,
		http
	} from '@/config/common.js'
	import bottom from '@/components/bottom.vue'
	export default {
		data() {
			return {
				c_value: 3,
				first: {},
				packList: [],
				id: '', //巡检id
				work_package_id: '', //包id
				site_id: '', //站点id
				baseInfo: {},

				covers: [],
				dataType:1,
			}
		},
		components: {
			bottom
		},
		filters: {},
		mounted() {
			this.$refs.bot.getDot()
		},
		onLoad(e) {
			this.id = e.id //巡检id
			this.work_package_id = e.work_package_id //包id

			this.initList()
		},
		onShow() {

		},
		onPageScroll(e) {},
		beforeDestroy() {},
		methods: {
			changeType(e){
				this.dataType = e
			},
			backXj() {
				uni.navigateTo({
					url: '/pages/xj/home'
				})
			},
			gotoInfo(item) { 
				if (item.status == 3 || item.status == 0) {
					uni.navigateTo({
						url: '/pages/xj/xcxj?id=' + this.id + '&packid=' + this.work_package_id + "&site_id=" +
							item.id
					})
				}
			},
			markTap(e) {
				let rst = e.detail
				let id = rst.markerId //站点id
				let dd = this.packList
				let current = {}
				dd.forEach(function(item) {
					if (item.id == id) {
						current = item
					}
				})
				if (current.status == 3 || current.status == 0) {
					uni.navigateTo({
						url: '/pages/xj/xcxj?id=' + this.id + '&packid=' + this.work_package_id + "&site_id=" + id
					})
				}

			},
			initList() {
				let that = this
				uni.showLoading({})
				api.post('api/shop/package_location', {
					onsite_id: this.id,
					work_package_id: this.work_package_id
				}).then(res => {
					uni.hideLoading()
					let rst = res.data
					that.packList = rst.data.list
					that.packList.forEach(function(item) {
						if (item.status == 3 || item.status == 0) {
							that.covers.push({
								id: item.id,
								latitude: item.latitude,
								longitude: item.longitude,
								iconPath: '/static/r.png',
								width: 30,
								height: 30
							})
						}
						if (item.status == 1 || item.status == 2) {
							that.covers.push({
								id: item.id,

								latitude: item.latitude,
								longitude: item.longitude,
								iconPath: '/static/g.png',
								width: 30,
								height: 30
							})
						}

					})

					that.first = rst.data.list[0]
					that.baseInfo = rst.data.work_packagelist

				}).catch(err => {
					uni.hideLoading()
				})
			},
		}
	};
</script>

<style scoped>
	.xj_map_type_item_active{
		color:#19afc9;
	}
	.xj_map_type{
		display: flex;
		flex-direction: row;
		justify-content: center;
	}
	.xj_map_type_item{
		font-size: 28rpx;
		font-weight: bold;
		margin-right: 10rpx;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
	}
	.kcsj_box_item_bottom {
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.kcsj_box_item_top_right_btn {
		border: 1px solid rgb(255, 118, 10);
		color: rgb(255, 118, 10);
		font-size: 25rpx;
		border-radius: 8rpx;
		padding: 0 10rpx;
		margin-right: 10rpx;
	}

	.kcsj_box_item_top_left {
		width: 80%;
		white-space: nowrap;
		/* 确保文本在一行内显示 */
		overflow: hidden;
		/* 超出容器的文本隐藏 */
		text-overflow: ellipsis;
		/* 超出部分显示省略号 */
	}

	.kcsj_box_item_top_right {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.kcsj_box_item_top {
		display: flex;
		flex-direction: row;
		align-items: center;
		font-size: 26rpx;
		justify-content: space-between;
	}

	.kcsj_box_item {
		width: 710rpx;
		margin: 0 auto;
		border: 1px solid rgb(235, 229, 229);
		padding: 20rpx;
		margin-top: 20rpx;
		border-radius: 10rpx;
	}

	.base_item_dd {
		word-wrap: break-word;
		overflow-wrap: break-word;
		white-space: normal;
		width: 80%;
	}

	.btn {
		width: 500rpx;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		margin: 0 auto;
		margin-top: 90rpx;
		background-color: rgb(70, 179, 255);
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}

	::v-deep .uni-input-input {
		font-size: 26rpx;
	}

	::v-deep .uni-input-placeholder {
		font-size: 26rpx;
	}

	.gcxt_b_wy_reason {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.gcxt_b_wy {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 20rpx 0;
	}

	.info_box_base {
		/* border: 1px solid rgb(235, 229, 229); */
		padding: 20rpx;
		font-size: 26rpx;
		margin-top: 20rpx;
	}

	.info_box_base_item {
		line-height: 50rpx;
	}

	.info_box {
		width: 710rpx;
		margin: 0 auto;

	}

	page {
		background-color: #fff;
		padding-bottom: 120rpx;
	}
</style>